<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>签约网</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>
</head>
<body>
<div id="secHeader">
  <header class="header">
      <a href="javascript:void(0);" onclick="api.closeWin()" class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>
      <h2>购买合同文书</h2>
      <!--<a href="news_find.html" class="search_btn"><img src="../image/search.png" alt=""></a>-->
  </header>
</div>
<section class="buy_flow">
    <div class="flow_list">
        <ul>
            <li><em>1</em><p>选择合同</p></li>
            <li><em>2</em><p>支付购买</p></li>
            <li><em>3</em><p>下载合同</p></li>
            <li><em>4</em><p>打开或发送</p></li>
        </ul>
    </div>
</section>
<section class="buy_order">
    <div class="product">
        <img src="../image/fyb_img.png" alt="">
        <div class="product_info">
            <p>签约网</p>
            <span>购买合同文书</span>
        </div>
    </div>
    <div class="pay_price">
        <p>支付金额</p>
        <span id='money'>￥50.00</span>
    </div>
    <div class="pay_kinds">
        <h6>选择支付方式</h6>
        <div class="pay_list">
            <ul>
                <li>
                    <div class="pay">
                        <img src="../image/pay1.png" alt="">
                        <div class="pay_info">
                            <p>支付宝</p>
                            <span>绿色充值通道，安全便捷</span>
                        </div>
                    </div>
                    <span class="checkbox"></span>
                </li>
                <li>
                    <div class="pay">
                        <img src="../image/pay2.png" alt="">
                        <div class="pay_info">
                            <p>微信</p>
                            <span>绿色充值通道，安全便捷</span>
                        </div>
                    </div>
                    <span class="checkbox"></span>
                </li>
                <li>
                    <div class="pay">
                        <img src="../image/pay3.png" alt="">
                        <div class="pay_info">
                            <p>账户余额</p>
                            <span></span>
                        </div>
                    </div>
                    <span class="tips"></span>
                    <span class="checkbox"></span>
                </li>
            </ul>
        </div>
    </div>
    <div class="pay_coupon">
        <p>选择优惠券</p>
        <span>不可用优惠券</span>
    </div>
    <div class="pay_deduction">
        <p>用邀请奖励余额抵扣</p>
        <span class="checkbox"></span>
    </div>
    <div class="pay-links">
        <p style="background: #fff;"><span id="money1" style="background: none;color:#f3a536">总金额：￥50.00</span></p>
        <a href="javascript:void (0);" class="link_btn" id='pay'>确认支付</a>
    </div>
</section>


</body>

<script>
    var para
    var money
    var type=0;
    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });

        para=api.pageParam;

        money=para.money
        $('#money').html('￥'+money)
        $('#money1').html('总金额：￥'+money)
    };


    //$('#balance').html('可用金额￥'+balance)



    $('#pay').click(function(){

        if(type == 0){
            alert('请选择支付方式！');return;
        }
        p={token:token,pay_type:type,type:14,money:money,id:para.id}
        api.ajax({
            url: webSiteUrl+'/Home/Ajax/order',
            method: 'post',
            data: {
                values: p
            }
        }, function(res, err) {
            if(res.code == 200){

                var orderno=res.msg
                if(type==1){
                    alipay(money,orderno)
                }else if(type==2){
                    wxpay(money,orderno)
                }else{
                    yepay(money,orderno)
                }


            }else{
                alert(res.msg);return false;

            }

        });

    });
    function alipay(money,orderno){
        var aliPayPlus = api.require('aliPayPlus');
        aliPayPlus.config({
            appId : appId,
            rsaPriKey : rsaPriKey,
        }, function(ret, err) {
            //alert(JSON.stringify(ret))
            if (ret.status == true) {
                aliPayPlus.pay({
                    subject : '签约网订单',
                    body : '签约网订单',
                    amount : '0.01',
                    tradeNO : orderno,
                    rsa2: true
                }, function(ret, err) {
                    if (ret.code == 9000) {
                        api.toast({
                            msg : '支付成功'
                        });
                        aaplay('personal');
                    } else {
                        if (ret.code == 6001) {
                            api.toast({
                                msg : '支付已取消'
                            });
                        } else {
                            alert('支付失败 code:' + err.code + err.msg);
                        }
                    }

                });
            }
        });
    }

    function wxpay(money,orderno){
        //alert(orderno);
        var wxPay = api.require('wxPay');
        wxPay.config({
            apiKey: apiKey,
            mchId: mchId,
            partnerKey: partnerKey,
            notifyUrl: notifyUrl
        }, function(ret, err) {
            if (ret.status) {
                //alert('配置商户支付参数成功');

                wxPay.pay({
                    description: '签约网订单',
                    totalFee: 1,
                    tradeNo: orderno,
                },function(ret,err){
                    //alert(JSON.stringify(ret));

                    if(ret.status) {
                        alert("您已支付成功");
                        aaplay('personal');
                    } else {
                        if(err.code == '-2'){
                            alert("您已取消支付");
                        } else {
                            alert('回调失败'+err.code+err.msg);
                        }
                    }
                });
            } else {
                alert(err.code);
            }
        });

    }
    //选择支付方式
    $(".pay_list li").click(function () {
        if($(this).find('.checkbox').length>0){
            $(this).addClass('active').siblings('li').removeClass('active');
        }

        type=parseInt($(this).index()+1)
    });

    //使用邀请抵扣
    $(".pay_deduction span").click(function () {
        if($(this).hasClass('active')){
            $(this).removeClass('active');
        }else {
            $(this).addClass('active');
        }
    })
</script>
</html>
